package com.yanfan.alarm.service.impl;

import java.util.Arrays;
import java.util.List;
import com.yanfan.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yanfan.alarm.mapper.IbmsAlarmRecordMapper;
import com.yanfan.alarm.domain.IbmsAlarmRecord;
import com.yanfan.alarm.service.IIbmsAlarmRecordService;

/**
 * 报警记录Service业务层处理
 *
 * @author genluo
 * @date 2024-09-24
 */
@Service
public class IbmsAlarmRecordServiceImpl extends ServiceImpl<IbmsAlarmRecordMapper, IbmsAlarmRecord> implements IIbmsAlarmRecordService {
    @Autowired
    private IbmsAlarmRecordMapper ibmsAlarmRecordMapper;


    /**
     * 查询报警记录列表
     *
     * @param ibmsAlarmRecord 报警记录
     * @return 报警记录
     */
    @Override
    public List<IbmsAlarmRecord> queryPageList(IbmsAlarmRecord ibmsAlarmRecord) {
        LambdaQueryWrapper<IbmsAlarmRecord> lqw = buildQueryWrapper(ibmsAlarmRecord);
//        return ibmsAlarmRecordMapper.selectList(lqw);
        //连表查询可用该方法，在此方法SQL语句上进行扩展
        return ibmsAlarmRecordMapper.queryPageList(ibmsAlarmRecord);
    }


    /**
     * 分页查询条件
     * @return
     */
    private LambdaQueryWrapper<IbmsAlarmRecord> buildQueryWrapper(IbmsAlarmRecord bo) {
        LambdaQueryWrapper<IbmsAlarmRecord> lqw = Wrappers.lambdaQuery();
        lqw.eq(StringUtils.isNotBlank(bo.getAlarmCode()), IbmsAlarmRecord::getAlarmCode, bo.getAlarmCode());
        lqw.eq(StringUtils.isNotBlank(bo.getChannel()), IbmsAlarmRecord::getDeviceId, bo.getDeviceId());
        lqw.eq(StringUtils.isNotBlank(bo.getChannel()), IbmsAlarmRecord::getChannel, bo.getChannel());
        lqw.eq(StringUtils.isNotBlank(bo.getSubChannel()), IbmsAlarmRecord::getSubChannel, bo.getSubChannel());
        lqw.eq(StringUtils.isNotBlank(bo.getAlarmTime()), IbmsAlarmRecord::getAlarmTime, bo.getAlarmTime());
        lqw.eq(bo.getUpdatedAt() != null, IbmsAlarmRecord::getUpdatedAt, bo.getUpdatedAt());
        lqw.orderByDesc(IbmsAlarmRecord ::getAlarmTime);
        return lqw;
    }



}
